if (typeof(API)=='undefined')
	API = {};
	
API.Template = function(tmp){
		var varreg = /([^{]+|[^}]+})/g;
		var field = /^{(.+)}$/;
		var toks = tmp.match(varreg);
		return {
			apply:function(obj){
				var arr = new Array();
				for(var i=0, c=toks.length; i<c; i++){
					var tok = toks[i];
					var name = tok.match(field);
					if (name==null || name.length!=2)
						arr.push(tok);
					else{
						var rep = obj[name[1]]; 
						if (rep==null)
							rep = name[0];
						arr.push(rep);
					}
				}
				return {
					'obj':obj,
					toString:function(){
						return arr.join('');
					}
				};
			}
		};
};
/*
var r = new API.Template("<{t} href='{l}'>{text}<{t}>");
var t = new API.Template("{ff} ut {aa} tam{bb}");
alert(t.apply({ff:'tu', aa:',',bb:r.apply({t:'a',text:'link',l:'http'})}));
*/